package com.reflection.homework;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class h2_修改字符串内容 {
    public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException {
        String s = "abc";
        String ss = "abc";

        Class clazz1 = s.getClass();
        Class clazz2 = ss.getClass();

        Field field = clazz1.getDeclaredField("value");
        field.setAccessible(true);

        //高版本不支持了
        byte[] bytes = (byte[]) field.get(s);
        bytes[0] = 100; //d 就是100    ASCII

        System.out.println(s);//dbc
        System.out.println(ss);//dbc
    }
}
